import {addWish,} from "./commonFunction";
import {getItemByItemId, updateCart} from "../../../src/api/api";
let nowUsername= sessionStorage.getItem("nowUsername");
export default {
  data(){
    return{
      itemId : "EST-1",
      username:"123",
      item: {
        name: "golden dog",
        productId : "",
        catId : "",
        itemId : "EST-1",
        nowPrice : 54,
        oldPrice : 90,
        supplier : "",
        descn : "beautiful,cute,clever",
        image : "../../static/picture/cart-1.jpg"
      },
      showItemList:[
        {
          itemId:"EST-10",
          productId:"K9-DL-01",
          categoryId:"DOGS",
          nowPrice:"18.50",
          oldPrice:"30.50",
          iName:"HERRY DOGS",
          iImage:"../../static/picture/i-dogs2.png",
          iDescn:"Spotted Adult Female.May you have enough happiness to make you sweet,enough trials to make you strong,enough sorrow to keep you human,enough hope to make you happy? Always put yourself in others’shoes."
        },
        {
          itemId:"EST-21",
          productId:"FI-FW-02",
          categoryId:"FISH",
          nowPrice:"5.29",
          oldPrice:"6.29",
          iName:"SO BIG FISH",
          iImage:"../../static/picture/i-fish3.png",
          iDescn:"Adult Female. The happiest of people don’t necessarily have the best of everything;they just make the most of everything that comes along their way.Happiness lies for those who cry,those who hurt, those who have searched"
        },
        {
          itemId:"EST-12",
          productId:"RP-SN-01",
          categoryId:"REPTILES",
          nowPrice:"18.50",
          oldPrice:"30.50",
          iName:"CUTE REPTILES",
          iImage:"../../static/picture/i-reptiles2.png",
          iDescn:"Rattleless.The happiest of people don’t necessarily have the best of everything;they just make the most of everything that comes along their way.Happiness lies for those who cry,those who hurt, those who have searched"
        },
        {
          itemId:"EST-16",
          productId:"FL-DSH-02",
          categoryId:"CATS",
          nowPrice:"93.50",
          oldPrice:"103.50",
          iName:"FFERT CATS",
          iImage:"../../static/picture/i-cats3.png",
          iDescn:"Adult Female. The happiest of people don’t necessarily have the best of everything;they just make the most of everything that comes along their way.Happiness lies for those who cry,those who hurt, those who have searched"
        }
      ]
    }
  },
  methods:{
    //添加到购物车
    addCart(itemId){
      let param = new FormData;
      param.append("increment", 1);
      console.log("加入购物车");
      updateCart(nowUsername,itemId,param).then((res) => {
        this.getItem();
        console.log("加入购物车成功");
        console.log(res);

      }).catch((res) => {
        alert("错误：" + res);
      });

    },
    addWish(itemId){
      let nowUsername= sessionStorage.getItem("nowUsername");
      if(nowUsername!=null){
        addWish(nowUsername,itemId);
      }else{
        alert("请先登录");}
    },
    chooseItem(itemId){
      for(let i = 0; i < this.showItemList.length; i++){
        if(itemId == this.showItemList[i].itemId){
          this.item = this.showItemList[i];
          break;
        }
      }
    }
  }
}
